table.FETCH_PREV Function

Syntax

Found_Flag as N = Fetch_Prev([fetch level])

Arguments

Found_Flag

The return value is zero if a record was found. A non-zero value indicates that a record was not found.

level

Optional. Used when fetching through the records of a set. The outline level determines the depth of the fetch, so that tables at lower levels in the set can be excluded from the Fetch operation.

Description

Fetch the previous record in the table/set. returns TRUE if record found.

Discussion

The <TBL>.FETCH_PREV() method retrieves the previous record in the table or set referenced by <TBL>. The previous record is determined by the active range, index, or query list. If there is no previous record to be fetched, the method returns a value other than zero. Use the <TBL>.FETCH_EOF() method after every <TBL>.FETCH_PREV()to determine if the function has tried to fetch beyond the active range and index. In most cases, the last current record is preserved when a <TBL>.FETCH_PREV()fails. You use the optional Outline_Level_Number parameter when fetching through the records of a set. The outline level determines the depth of the fetch, so that tables at lower levels in the set can be excluded from the Fetch operation. This is useful for operations that relate to only parent records in a set. For more information, see Fetching Only Parent Records With Fetch Outlining.

Example

This script is attached to a button on a form. It fills the state_prov field in the current record with the value from the previous record in the current sorted order. If the current record is in change or enter mode when the button is pressed, it preserves the record entry state.

dim prev_value as C
tbl = table.current()
'Check what mode the table is in
mode = tbl.mode_get()
if (mode = 0) then                    'table is in view mode
    tbl.fetch_prev()
    prev_value = tbl.state_prov
    state_prov.value = prev_value

The object on the form that displays the state_prov field is called state_prov. Set its value.

parent.commit()            'Save the record
else
    'Table is not in view mode, so we cannot move the record pointer.
    'A new instance of the table must be opened.
    tbl2 = table.open(a_db_current)
    'get reference to current index
    indx_tbl = tbl.index_primary_get()
    'get the record number
    recno = tbl.recno()
    'Get index tag name in the first instance of the table.
    if (indx_tbl.type_get()= -1) then      'check if recno order
      indx_tbl_name = ""
    else
        indx_tbl_name = indx_tbl.name_get()
    end if
    indx_tbl2 = tbl2.index_primary_put(indx_tbl_name)
    tbl2.fetch_goto(recno)
    'Move to the previous record in the tbl2
    tbl2.fetch_prev()
    prev_value = tbl2.state_prov
    state_prov.value = prev_value
end if

See Also